<template>
    <view style="height: 100%">
        <ul class="db" v-if="list.length != 0">
            <block v-for="(item, index) in list" :key="index">
                <li class="bgcf pd15 df ac mb10">
                    <view class="f1 ml12" @tap="onSel" :data-item="item">
                        <p class="f14 c3 f600 df">
                            <span>{{ item.username }}</span>
                            <span class="ml8">{{ item.mobile }}</span>
                        </p>
                        <p class="f14 mt5 db">
                            <span class="cf5" v-if="item.check == 1">[默认]</span>
                            <span class="c6">{{ item.add }}</span>
                        </p>
                        <p class="f12 c6 df mt5">
                            <span>{{ item.company }}</span>
                            <span class="ml8">{{ item.taxpayer_number }}</span>
                        </p>
                        <p class="f12 c6 df mt5" v-if="item.bank">
                            <span>{{ item.bank }}</span>
                            <span class="ml8">{{ item.account }}</span>
                        </p>
                    </view>
                    <navigator class="img16 ml15 edit" :url="'/pages/address/address?id=' + item.id" hover-class="none" open-type="navigate"></navigator>
                </li>
            </block>
        </ul>

        <view class="df jc mt30" v-else>
            <image src="https://wx.xtwaixie.com/img/empty.png" class="w50" mode="aspectFit"></image>
        </view>
        <view class="pd1015 bgcf pob">
            <navigator class="pob-but" url="/pages/address/address?id=0" hover-class="none" open-type="navigate">添加新地址</navigator>
        </view>
    </view>
</template>

<script>
import http from '../../utils/http';
export default {
    data() {
        return {
            list: [],
            type: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        this.setData({
            type: options.type
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.setData({
            list: []
        });
        this.getList();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        onGoDetail() {
            console.log(123);
        },

        getList() {
			const token = uni.getStorageSync('token')
			if(!token){
				return
			}
            http.request('Address/addList')
                .then((res) => {
                    // res.data.list.forEach((i) => {
                    //   i.is_check = false;
                    // });
                    this.setData({
                        list: res.data
                    });
                })
                .catch((res) => {
                    uni.showToast({
                        title: res.message,
                        icon: 'none'
                    });
                });
        },

        onSel(e) {
            let type = this.type;
            if (type == 1) {
                return false;
            }
            let item = e.currentTarget.dataset.item;
            uni.setStorageSync('address_info', item);
            uni.navigateBack({
                delta: 1
            });
        }
    }
};
</script>
<style>
@import './addressList.css';
</style>
